//管理动作的顿帧配置
using UnityEngine.Rendering;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class HitlagService : FSMServiceiBase
{
    public override void OnAnimationEnd(PlayerState state)
    {
        base.OnAnimationEnd(state);
    }

    public override void OnBegin(PlayerState state)
    {
        base.OnBegin(state);
        ReSetAllExcuted();
    }

    public override void OnEnd(PlayerState state)
    {
        base.OnEnd(state);
        ReSetAllExcuted();
    }

    public override void OnUpdate(float normalizedTime, PlayerState state)
    {
        base.OnUpdate(normalizedTime, state);
        if (state.stateEntity.hitlagConfigs != null)
        {
            if (state.stateEntity.hitlagConfigs.Count > 0)
            {
                for (int i = 0;i< state.stateEntity.hitlagConfigs.Count; i++)
                {
                    var x  = state.stateEntity.hitlagConfigs[i];
                    if(x.triggerType==0 && normalizedTime >= x.trigger && GetExecuted(i) ==false)
                    {
                        SetExcuted(i);
                        GameEvent.DoHitlag?.Invoke(x.frame, x.lerp);
                    }
                    
                }
            }
        }
    }

    public override void ReLoop(PlayerState state)
    {
        base.ReLoop(state);
    }

    public override void ReStart(PlayerState state)
    {
        base.ReStart(state);
    }

    

    public void DoHitlag_OnAttack(float anmNormalzedTime,PlayerState state)
    {
        if (state.stateEntity.hitlagConfigs.Count > 0)
        {
            for (int i = 0; i < state.stateEntity.hitlagConfigs.Count; i++)
            {
                var x = state.stateEntity.hitlagConfigs[i];
                if (x.triggerType == 1 && anmNormalzedTime >= x.trigger && anmNormalzedTime <= x.trigger2)
                {
                    GameEvent.DoHitlag?.Invoke(x.frame, x.lerp);
                }

            }
        }
    }
}